package com.java1412.utils;

/**
 * 统一返回给浏览器的结果
 *
 * @author java1412
 * @since 2023-08-07 09:16:59
 */
public class ResponseUtil {

    private Integer code; // 状态码

    private String msg;     // 消息

    private Object data;    // 数据

    private ResponseUtil() {
    }

    private ResponseUtil(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    // 成功不带数据
    public static ResponseUtil ok(String msg) {
        return new ResponseUtil(200, msg);
    }

    // 成功带数据
    public static ResponseUtil ok(String msg, Object data) {
        ResponseUtil r = new ResponseUtil(200, msg);
        r.setData(data);
        return r;
    }

    // 失败
    public static ResponseUtil fail(String msg) {
        return new ResponseUtil(400, msg);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
